package com.kyin.satoken.filter;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.kyin.satoken.exception.GlobalException;
import com.kyin.satoken.utils.CryptoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

/**
 * @author yin.kai
 * @ClassName RequestLogFilter
 * @description: 类描述
 * @date 2025/9/24 9:34
 * @version: 1.0
 */
@Component
@Slf4j
public class RequestParamsFilter extends OncePerRequestFilter {


    @Value("${magic-api.prefix}")
    private String magicPrefix;

    private static final String MAGIC_URL_KEY = "reqUrl";


    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        log.info("请求路径:{}",request.getRequestURI());
        if(request.getServletPath().indexOf(magicPrefix)>-1){
            filterChain.doFilter(request,response);
            return;
        }
        filterChain.doFilter(new RequestParamsRequestWrapper(request,magicPrefix),response);
    }

}
